package net.destroyer.game.tetris.gui.menu;

import java.util.HashMap;
import java.util.Map;

import javax.swing.JMenu;
import javax.swing.JSeparator;

import net.destroyer.game.tetris.gui.MainWindow;
import net.destroyer.game.tetris.gui.Messages;
import net.destroyer.game.tetris.gui.State;
import net.destroyer.game.tetris.gui.control.ExitCommand;
import net.destroyer.game.tetris.gui.menu.interf.IUpdate;

public class GameMenu extends JMenu implements IUpdate{

	private static final long serialVersionUID = -639649978458939274L;
	private static String NEWGAME = Messages.getString("GameMenu.new"); //$NON-NLS-1$
	private static String EXIT= Messages.getString("GameMenu.exit"); //$NON-NLS-1$
	private static String GAME= Messages.getString("GameMenu"); //$NON-NLS-1$
	Map<String,AppMenuitem> comp;
	
	public GameMenu(MainWindow w) {
		this.setText(GAME);
		this.comp = new HashMap<String, AppMenuitem>();
		
		AppMenuitem n = new AppMenuitem(NEWGAME);
		comp.put(NEWGAME, n);
		this.add(n);
		
		this.add(new JSeparator());
		
		AppMenuitem x = new AppMenuitem(EXIT);
		x.setGuiCommand(w.getCommand(ExitCommand.class.getName()));
		comp.put(EXIT, x);
		this.add(x);
	}

	@Override
	public void update(State state) {
		switch (state) {
		case OPEN:
			this.setEnabled(true);
			this.comp.get(NEWGAME).setEnabled(true);
			this.comp.get(EXIT).setEnabled(true);
			break;

		default:
			break;
		}
	}
}
